﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.Profinet.AllenBradley;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 三菱PLC的EIP协议的实现，当PLC使用了 QJ71EIP71 模块时就需要使用本类来访问
	/// </summary>
	// Token: 0x02000068 RID: 104
	public class MelsecCipNet : AllenBradleyNet
	{
		/// <inheritdoc cref="M:HslCommunication.Profinet.AllenBradley.AllenBradleyNet.#ctor" />
		// Token: 0x06000876 RID: 2166 RVA: 0x00024C5C File Offset: 0x00022E5C
		public MelsecCipNet()
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.AllenBradley.AllenBradleyNet.#ctor(System.String,System.Int32)" />
		// Token: 0x06000877 RID: 2167 RVA: 0x00024C66 File Offset: 0x00022E66
		public MelsecCipNet(string ipAddress, int port = 44818) : base(ipAddress, port)
		{
		}

		/// <summary>
		/// Read data information, data length for read array length information
		/// </summary>
		/// <param name="address">Address format of the node</param>
		/// <param name="length">In the case of arrays, the length of the array </param>
		/// <returns>Result data with result object </returns>
		// Token: 0x06000878 RID: 2168 RVA: 0x0002DC9C File Offset: 0x0002BE9C
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			return base.Read(new string[]
			{
				address
			}, new int[]
			{
				(int)length
			});
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecCipNet.Read(System.String,System.UInt16)" />
		// Token: 0x06000879 RID: 2169 RVA: 0x0002DCC8 File Offset: 0x0002BEC8
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			MelsecCipNet.<ReadAsync>d__3 <ReadAsync>d__ = new MelsecCipNet.<ReadAsync>d__3();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<MelsecCipNet.<ReadAsync>d__3>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}
	}
}
